package com.huike.web.controller.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.read.listener.ReadListener;
import com.huike.clues.domain.vo.TbClueExcelVo;
import com.huike.clues.service.ITbClueService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Slf4j
@Component
public class excelClueListener implements ReadListener<TbClueExcelVo> {

    @Autowired
    private ITbClueService clueService;

    /**
     * 读取excel 头部信息
     */
    @Override
    public void invokeHead(Map<Integer, ReadCellData<?>> headMap, AnalysisContext context) {
        //for (Map.Entry<Integer, ReadCellData<?>> dataEntry : headMap.entrySet()) {
        //    System.out.println(dataEntry.getValue().getStringValue());
        //}
    }

    /**
     * 读取excel文件中的内容
     *
     * @param data excel表中 每一行对应 的java 实体类
     */
    @Override
    public void invoke(TbClueExcelVo data, AnalysisContext context) {
        //boolean b=clueService.addTbClue(data);
        //System.out.println(data);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
        log.info("excel 文件解析完毕");
    }
}
